<?php 
	echo $this -> Html -> css(array('setting.css'));
	echo $this -> Html -> script(array('setting.js', 'jquery.validate.js'));
	//$arr7Day = array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7');
    $optionId = 1;
?>
<?php
	function convertTime($time) {
		if ($time < 10) {
			$time = '0' . $time;
		}
		return $time;
	} 
?>
<style>
label.error
{
    color: red;
}
</style>
<div class="setting_border_main">
    <?php
        echo $this -> Form -> create('Setting', array('data-ajax' => 'false', 'id' => 'pc_setting'));
    ?>
    <input type="hidden" id="hdFlg" name="hdFlg">
    <input type="hidden" id="hd_rank" value="<?php echo $rank?>" >
    <div style="margin: 10px 60px 50px 60px; width:90%">
    	<div class="setting_background_title_4"></div>
        <div style="float: left;">
            <div class="border_2_title_1"></div>
            <div style="float:left;">
                <?php 
                    $int7Day1 = 1;
                    while ($int7Day1 < 9) {
                        echo "<div class='setting_title_button'>";
                        echo "<div class='setting_title_" . $int7Day1 . "'></div>";
                        echo "<div>";
                        if ($arrStatus[$int7Day1 - 1] == 1) {
                            echo "<input class='setting_button_1' type='button' id='btnClear" 
                            	 . $int7Day1 
                            	 . "' name='btnClear" 
                            	 . $int7Day1 
                            	 . "' onclick='setVisable(1," 
                            	 . $int7Day1 
                            	 . ")' value=''>";
                        } else {
                            echo "<input class='setting_button_2' type='button' id='btnClear" 
                            	 . $int7Day1 
                            	 . "' name='btnClear" 
                            	 . $int7Day1 
                            	 . "' onclick='setVisable(2," 
                            	 . $int7Day1 
                            	 . ")' value=''>";
                        }
                        echo "</div></div>";
                        $int7Day1++;
                    }
                ?>
            </div>
        </div>
        <div style="width:300px; float: left; background: #ECF2FE; border-bottom: 1px solid #707071; border-left: 1px solid #707071;">
        <div class='border_2_title_2'></div>
        <?php 
        $int7Day2 = 2;
        while ($int7Day2 < 10) {
        	echo "<div class='setting_set_plan setting_set_planMorning' index=" . $optionId . ">";
        	echo "<select id='startMorningH_" . $optionId . "' name='startMorningH[" . $optionId
	        	. "]' class='setting_width_2_status" . $arrStatus[$int7Day2 - 2] . " startMor'>";
            $flagMorningStart = null;
            for ($i = 7 ; $i < 23 ; $i++) {
                if ($arrStartMorning[$int7Day2 - 2] == $i) {
                    $flagMorningStart = $i;
                    echo "<option value='" . $i . "' selected='selected'>" . $i . "</option>";          
                } else {
                    echo "<option value='" . $i . "'>" . $i . "</option>";  
                }
            }            
            echo "</select>";
            echo "時";
            //start morning minute
            echo "<select id='startMorningM_" . $optionId . "' name='startMorningM[" . $optionId
	            . "]' class='setting_width_2_status" . $arrStatus[$int7Day2 - 2] . " startMorMin'>";
            for ($i = 0 ; $i < 60 ; $i+=$rank) {
                if ($arrStartMorningMinute[$int7Day2 - 2] == $i) {
                    echo "<option value='" . $i . "' selected='selected'>" . $i . "</option>";          
                } else {
                    echo "<option value='" . $i . "'>" . $i . "</option>";  
                }
            }
            echo "</select>";
            echo "分 ~ ";

            echo "<select id='endMorningH_" . $optionId . "' name='endMorningH[" . $optionId
	            . "]' class='setting_width_2_status" . $arrStatus[$int7Day2 - 2] . " endMor'>";
            if ($flagMorningStart == null) {
                $numberMorningStart = 7;
            } else {                
                $numberMorningStart = $flagMorningStart;
            }
            for ($i = $numberMorningStart ; $i < 23 ; $i++) {
                if ($arrEndMorning[$int7Day2 - 2] == $i) {
                    echo "<option value='" . $i . "' selected='selected'>" . $i . "</option>";          
                } else {
                    echo "<option value='" . $i . "'>" . $i . "</option>";  
                }
            }
            echo "</select>";
            echo "時";

            //end morning minute
            echo "<select id='endMorningM_" . $optionId . "' name='endMorningM[" . $optionId
	            . "]' class='setting_width_2_status" . $arrStatus[$int7Day2 - 2] . " endMorMin'>";
            for ($i = 0 ; $i < 60 ; $i+=$rank) {
                if ($arrEndMorningMinute[$int7Day2 - 2] == $i) {
                    echo "<option value='" . $i . "' selected='selected'>" . $i . "</option>";          
                } else {
                    echo "<option value='" . $i . "'>" . $i . "</option>";  
                }
            }
            echo "</select>";
            echo "分";
            
            echo "</div>";
            $optionId++;
            $int7Day2++;                        
        }
        $optionId = 1;
        ?>
        </div>
        
        <div style="width:300px; float: left; background: #ECF2FE; border-bottom: 1px solid #707071; border-left: 1px solid #707071;">
        <div class='border_2_title_4'></div>
        <?php 
        $int7Day2 = 2;
        while ($int7Day2 < 10) {
            echo "<div class='setting_set_plan setting_set_planAfternoon' index=" . $optionId . ">";
            echo "<select id='startAfternoonH_" . $optionId . "' name='startAfternoonH[" . $optionId
            	. "]' class='setting_width_2_status" . $arrStatus[$int7Day2 - 2] . " startAft'>";
            $flagAfternoonStart = null;
            for ($i = 7 ; $i < 23 ; $i++) {
                if ($arrStartAfternoon[$int7Day2 - 2] == $i) {
                    echo "<option value='" . $i . "' selected='selected'>" . $i . "</option>";      
                    $flagAfternoonStart = $i;
                } else {
                    echo "<option value='" . $i . "'>" . $i . "</option>";  
                }
            }
            echo "</select>";
            echo "時";
            
            //start Afternoon Minute
            echo "<select id='startAfternoonM_" . $optionId . "' name='startAfternoonM[" . $optionId
            	. "]' class='setting_width_2_status" . $arrStatus[$int7Day2 - 2] . " startAftMin'>";
            for ($i = 0 ; $i < 60 ; $i+=$rank) {
                if ($arrStartAfternoonMinute[$int7Day2 - 2] == $i) {
                    echo "<option value='" . $i . "' selected='selected'>" . $i . "</option>";      
                } else {
                    echo "<option value='" . $i . "'>" . $i . "</option>";  
                }
            }
            echo "</select>";
            echo "分 ~ ";
            
            echo "<select id='endAfternoonH_" . $optionId . "' name='endAfternoonH[" . $optionId
            	. "]' class='setting_width_2_status" . $arrStatus[$int7Day2 - 2] . " endAft'>";
            if ($flagAfternoonStart == null) {
                $numberAfternoonStart = 7;
            } else {                
                $numberAfternoonStart = $flagAfternoonStart;
            }
            for ($i = $numberAfternoonStart ; $i < 23 ; $i++) {
                if ($arrEndAfternoon[$int7Day2 - 2] == $i) {
                    echo "<option value='" . $i . "' selected='selected'>" . $i . "</option>";          
                } else {
                    echo "<option value='" . $i . "'>" . $i . "</option>";
                }
            }
            echo "</select>";
            echo "時";
            
            //end afternoon minute
            echo "<select id='endAfternoonM_" . $optionId . "' name='endAfternoonM[" . $optionId
            	. "]' class='setting_width_2_status" . $arrStatus[$int7Day2 - 2] . " endAftMin'>";
            for ($i = 0 ; $i < 60 ; $i+=$rank) {
                if ($arrEndAfternoonMinute[$int7Day2 - 2] == $i) {
                    echo "<option value='" . $i . "' selected='selected'>" . $i . "</option>";          
                } else {
                    echo "<option value='" . $i . "'>" . $i . "</option>";
                }
            }
            echo "</select>";
            echo "分";
            
            echo "</div>";
            $int7Day2++;    
            $optionId++;                    
        }
        ?>
        </div>
        <div class="setting_background_title_5"></div>
        <div class="setting_rank">        
        <select name="rank" id="rank">
           <?php 
                for ($i = 5 ; $i <= 30 ; $i = $i + 5) {
                    if ($i != 25) {
                        if ($rank == $i) {
                            echo "<option value='" . $i . "' selected='selected'>" . $i . "</option>";          
                        } else {
                            echo "<option value='" . $i . "'>" . $i . "</option>";  
                        }
                    }
                }
           ?>
        </select>&nbsp;分
    	</div>
        <div class="label_1">
            <div class="sub_title1">診療時間・診療間隔を入力後、登録ボタンを押してください。</div>
            <input class="button_save_plan" type="button" id="btnSave1" onclick="saveOption()" name="btnSave1" value="">
        </div>
        <div style="clear: both;"></div>
        <div class="content_block">設定例 </div>
        <br>
        <hr>
        <br>
        <br>
        <div id="addArea">     
            <table>
                <tr>
                    <td class="setting_background_title_3">
                    </td>
                    <td>
                        <div class="setting_margin_1">
	                        <input class="setting_width_1" type='text' name='year' id='year' maxlength="4" style="ime-mode:disabled;">年
	                        <input class="setting_width_1" type='text' name='month' id='month' maxlength="2" style="ime-mode:disabled;">月
	                        <input class="setting_width_1" type='text' name='day' id='day' maxlength="2" style="ime-mode:disabled;">日
                        </div>
                    </td>
                    <td>
                    	<div class="setting_margin_2">
	                    	<div class="setting_margin_3">時間指定のある場合 </div>
	                    </div>
                        <div class="timeArea">
                        	<p class='first'>
		                        <select name='startHour' id="startHour">
		                            <?php 
		                                for ($i = 7;$i < 23; $i++) {
		                                    echo "<option value=" . $i . ">" . $i . "</option>";
		                                }
		                            ?>
		                        </select>
		                        	時
		                        <select name='startMinute' id="startMinute">
		                            <?php 
		                                for ($i = 0;$i < 60; $i += $rank) {
		                                    echo "<option value=" . $i . ">" . $i . "</option>";
		                                }
		                            ?>
		                        </select>
		                        	分
		                    </p>
		                    <p class='last'>
		                        	~ 
		                        <select name='endHour' id="endHour">
		                            <?php 
		                                for ($i = 7;$i < 23; $i++) {
		                                    echo "<option value=" . $i . ">" . $i . "</option>";
		                                }
		                            ?>
		                        </select>
		                        	時
		                        <select name='endMinute' id="endMinute">
		                            <?php 
		                                for ($i = 0;$i < 60; $i += $rank) {
		                                    echo "<option value=" . $i . ">" . $i . "</option>";
		                                }
		                            ?>
		                        </select>
		                        	分
		                    </p>
	                    </div>
                    </td>
                </tr>
            </table>                 
        </div>      
        <div id="main">
            <div class="label_1">
                <div>複数登録する際は、１回ずつ登録して下さい。</div>
                <input class="button_save_plan" type='button' id="btnSave2" name='btnSave2' 
                onclick="saveVacationWithTime()" value=''>
            </div>
            <div style="clear: both;"></div>
            <div class="content_block">設定例 </div>
            <div>
                表示切替：<select name="searchMonth" id="searchMonth">
                            <option value="0">全て</option>
                            <?php 
                                for ($i = 1;$i <13; $i++) {
                                    echo "<option value=" . $i . ">" . $i . "</option>";
                                }
                            ?>
                      </select>
                      <input type="button" name="choose" class="setting_button_search" id="choose" 
                      onclick="searchMonthVacation()" value="">
            </div>
            <div>
                <table border="1px;" id="tableVacation">
                	<thead>
	                    <tr>
	                        <th class="setting_vacation_header first"></th>
	                        <th class="setting_vacation_header second">日付</th>
	                        <th class="setting_vacation_header third">時間</th>
	                        <th class="setting_vacation_header forth">アクション</th>
	                    </tr>
	                </thead>
                    <tbody>
                        <?php
                            foreach ($vacationArray as $vacation) {
                                echo "<tr>";
                                echo "<td class='setting_vacation_1'>臨時休み</td>";
                                echo "<td>" . $vacation['Vacation']['date'] . "</td>";
                                if ($vacation['Vacation']['timeStart'] == null) {
                                    echo "<td>なし</td>";
                                } else {
                                    echo "<td>" . convertTime($vacation['Vacation']['timeStart']) . '時' .  convertTime($vacation['Vacation']['timeStartM']) . '分   ～ ' . convertTime($vacation['Vacation']['timeEnd']) . "時" . convertTime($vacation['Vacation']['timeEndM']) . "分</td>";
                                }
                                echo "<td><input type='button' name='delete' id='delete' class='setting_button_delete' value='' onclick='deleteVacation(" . $vacation['Vacation']['id'] . ")' ></td>";
                                echo "</tr>";
                            }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
        <br>
        <br>
        <hr>
        <br>        
        <div style="float: left; width: 100%;">
	        <table width="100%">
	        	<tr>
	        		<td class="setting_background_title_1">
	        		</td>
	        		<td>
	        			<span class="setting_margin_1">
	                        <input class="setting_width_1" type='text' name='txtFromYear' id='txtFromYear' maxlength="4">年
	                        <input class="setting_width_1" type='text' name='txtFromMonth' id='txtFromMonth' maxlength="2">月
	                        <input class="setting_width_1" type='text' name='txtFromDay' id='txtFromDay' maxlength="2">日
                        </span>
                        <span class="setting_margin_1">
	                                                                  から
                        </span>
	                    <span class="setting_margin_1">
	                        <input class="setting_width_1" type='text' name='txtToYear' id='txtToYear' maxlength="4">年
	                        <input class="setting_width_1" type='text' name='txtToMonth' id='txtToMonth' maxlength="2">月
	                        <input class="setting_width_1" type='text' name='txtToDay' id='txtToDay' maxlength="2">日
                        </span>
                        <span class="setting_margin_1">
	                                                                  まで
                        </span>
	        		</td>
	        	</tr>
	        </table>	        
	    </div>
	    <div style="clear: both;"></div>
		<div>
			<div class="label_1">
                <input class="button_save_plan" type='button' id="btnSave3" name='btnSave3' 
                onclick="saveVacationWithoutTime()" value=''>
            </div>
            <div style="clear: both;"></div>
            <div class="content_block">設定例 </div>
            <br>
            <div>
            	<table border="1px;" id="tableVacation0">
            		<thead>
	                    <tr>
	                        <th class="setting_vacation_header first"></th>
	                        <th class="setting_vacation_header second">日付</th>
	                        <th class="setting_vacation_header forth">アクション</th>
	                    </tr>
	                </thead>
                    <tbody>
                        <?php
                            foreach ($vacationArrayFromTo as $vacationFromTo) {
                                echo "<tr>";
                                echo "<td class='setting_vacation_0'>年末年始休診</td>";
                                echo "<td>" . $vacationFromTo['Vacation']['date'] . "</td>";                                
                                echo "<td><input type='button' name='delete' class='setting_button_delete' id='delete' value='' onclick='deleteVacationWithoutTime(" . $vacationFromTo['Vacation']['id'] . ")' ></td>";
                                echo "</tr>";
                            }
                        ?>
                    </tbody>
                </table>
            </div>
		</div>
	    <br>
	    <br>
	    <hr>
	    <br>
	    <div style="float: left; width: 100%;">
	        <div class="setting_background_title_2">
	        	&nbsp;
	        </div>
	        <div class="vacationLast">
	        	<table border="1">
	        		<thead>
		        		<tr>
		        			<th class="setting_vacation_header first">日付</th>
		        			<th class="setting_vacation_header specific">説明</th>
		        		</tr>
		        	</thead>
		        	<tbody>
		        		<?php
                            foreach ($arrGoogleCalendar as $content => $startTime) {
                            	$content = explode('/', $content);
                                echo "<tr>";
                                echo "<td>" . $startTime . "</td>";                                
                                echo "<td>" . $content[0] . "</td>";   
                                echo "</tr>";
                            }
                        ?>
		        	</tbody>
	        	</table>
	        </div>
        </div>
        <br>
    </div>
    <?php
        echo $this -> Form -> end();
    ?>
</div>